home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Exchange
/
CD Exchange - Volume 1.iso
/
games
/
pd
/
chess
/
src.lha
/
src
/
dspcom.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-07
|
30KB
|
1,324 lines
/*
* dspcom.c - C source for GNU CHESS
*
* Copyright (c) 1988,1989,1990 John Stanback
* Copyright (c) 1992 Free Software Foundation
*
* This file is part of GNU CHESS.
*
* GNU Chess is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Chess is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Chess; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "gnuchess.h"
#include "ataks.h"
extern short Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
extern char *version, *patchlevel;
char mvstr[4][6];
char *InPtr;
#include <ctype.h>
#include <signal.h>
#ifdef MSDOS
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#else
#ifndef AMIGA
#include <sys/param.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#define WarnMessage ShowMessage
#else
#include <sys/types.h>
extern int get_command;
#endif /* AMIGA */
#endif /* MSDOS */
void
algbr (short int f, short int t, short int flag)
/*
* Generate move strings in different formats.
*/
{
int m3p;
if (f != t)
{
/* algebraic notation */
mvstr[0][0] = cxx[column (f)];
mvstr[0][1] = rxx[row (f)];
mvstr[0][2] = cxx[column (t)];
mvstr[0][3] = rxx[row (t)];
mvstr[0][4] = mvstr[3][0] = '\0';
if (((mvstr[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
{
if (mvstr[0][0] == mvstr[0][2]) /* pawn did not eat */
{
mvstr[2][0] = mvstr[1][0] = mvstr[0][2]; /* to column */
mvstr[2][1] = mvstr[1][1] = mvstr[0][3]; /* to row */
m3p = 2;
}
else
/* pawn ate */
{
mvstr[2][0] = mvstr[1][0] = mvstr[0][0]; /* column */
mvstr[2][1] = mvstr[1][1] = mvstr[0][2]; /* to column */
mvstr[2][2] = mvstr[0][3];
m3p = 3; /* to row */
}
if (flag & promote)
{
mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
mvstr[0][5] = mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[3][0] = '\0';
#ifdef CHESSTOOL
mvstr[3][0] = mvstr[0][0]; /* Allow e7e8 for chesstool */
mvstr[3][1] = mvstr[0][1];
mvstr[3][2] = mvstr[0][2];
mvstr[3][3] = mvstr[0][3];
mvstr[3][4] = '\0';
#endif
}
mvstr[2][m3p] = mvstr[1][2] = '\0';
}
else
/* not a pawn */
{
mvstr[2][0] = mvstr[1][0];
mvstr[2][1] = mvstr[0][1];
mvstr[2][2] = mvstr[1][1] = mvstr[0][2]; /* to column */
mvstr[2][3] = mvstr[1][2] = mvstr[0][3]; /* to row */
mvstr[2][4] = mvstr[1][3] = '\0';
strcpy (mvstr[3], mvstr[2]);
mvstr[3][1] = mvstr[0][0];
if (flag & cstlmask)
{
if (t > f)
{
strcpy (mvstr[1], CP[5]);
strcpy (mvstr[2], CP[7]);
}
else
{
strcpy (mvstr[1], CP[6]);
strcpy (mvstr[2], CP[8]);
}
}
}
}
else
mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
}
int
VerifyMove (char *s, short int iop, unsigned short int *mv)
/*
* Compare the string 's' to the list of legal moves available for the
* opponent. If a match is found, make the move on the board.
*/
{
static short pnt, tempb, tempc, tempsf, tempst, cnt;
static struct leaf xnode;
struct leaf *node;
*mv = 0;
if (iop == 2)
{
UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
return (false);
}
cnt = 0;
MoveList (opponent, 2);
pnt = TrPnt[2];
while (pnt < TrPnt[3])
{
node = &Tree[pnt++];
algbr (node->f, node->t, (short) node->flags);
if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0)
{
cnt++;
xnode = *node;
}
}
if (cnt == 1)
{
MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst, &INCscore);
if (SqAtakd (PieceList[opponent][0], computer))
{
UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
#if defined CHESSTOOL
printz (CP[15]);
#else
#ifdef NONDSP
/* Illegal move in check */
printz (CP[77]);
printz ("\n");
#else
/* Illegal move in check */
WarnMessage (CP[77]);
#endif
#endif /* CHESSTOOL */
return (false);
}
else
{
if (iop == 1)
return (true);
UpdateDisplay (xnode.f, xnode.t, 0, (short) xnode.flags);
if ((board[xnode.t] == pawn)
|| (xnode.flags & capture)
|| (xnode.flags & cstlmask))
{
Game50 = GameCnt;
ZeroRPT ();
}
GameList[GameCnt].depth = GameList[GameCnt].score = 0;
GameList[GameCnt].nodes = 0;
ElapsedTime (1);
GameList[GameCnt].time = et;
if (TCflag)
{
TimeControl.clock[opponent] -= et;
--TimeControl.moves[opponent];
}
*mv = (xnode.f << 8) | xnode.t;
algbr (xnode.f, xnode.t, false);
return (true);
}
}
#if defined CHESSTOOL
printz (CP[78]);
#else
#ifdef NONDSP
/* Illegal move */
printz (CP[75], s);
#ifdef DEBUG8
if (1)
{
FILE *D;
int r, c, l;
extern unsigned short int PrVar[];
D = fopen ("/tmp/DEBUG", "a+");
pnt = TrPnt[2];
fprintf (D, "resp = %d\n", ResponseTime);
fprintf (D, "iop = %d\n", iop);
fprintf (D, "matches = %d\n", cnt);
algbr (hint >> 8, hint & 0xff, (short) 0);
fprintf (D, "hint %s\n", mvstr[0]);
fprintf (D, "inout move is %s\n", s);
for (r = 1; PrVar[r]; r++)
{
algbr (PrVar[r] >> 8, PrVar[r] & 0xff, (short) 0);
fprintf (D, " %s", mvstr[0]);
}
fprintf (D, "\n");
fprintf (D, "legal move are \n");
while (pnt < TrPnt[3])
{
node = &Tree[pnt++];
algbr (node->f, node->t, (short) node->flags);
fprintf (D, "%s %s %s %s\n", mvstr[0], mvstr[1], mvstr[2], mvstr[3]);
}
fprintf (D, "\n current board is\n");
for (r = 7; r >= 0; r--)
{
for (c = 0; c <= 7; c++)
{
l = locn (r, c);
if (color[l] == neutral)
fprintf (D, " -");
else if (color[l] == white)
fprintf (D, " %c", qxx[board[l]]);
else
fprintf (D, " %c", pxx[board[l]]);
}
fprintf (D, "\n");
}
fprintf (D, "\n");
fclose (D);
abort ();
}
#endif
#else
/* Illegal move */
WarnMessage (CP[76]);
#endif
#endif /* CHESSTOOL */
#if !defined CHESSTOOL && !defined XBOARD
if (cnt > 1)
WarnMessage (CP[32]);
#endif /* CHESSTOOL */
return (false);
}
int
parser (char *f, int side)
{
int c1, r1, c2, r2;
if (f[4] == 'o')
if (side == black)
return 0x3C3A;
else
return 0x0402;
else if (f[0] == 'o')
if (side == black)
return 0x3C3E;
else
return 0x0406;
else
{
c1 = f[0] - 'a';
r1 = f[1] - '1';
c2 = f[2] - 'a';
r2 = f[3] - '1';
return (locn (r1, c1) << 8) | locn (r2, c2);
}
/*NOTREACHED*/
}
void
GetGame (void)
{
FILE *fd;
char fname[256], *p;
int c, i, j;
short sq;
/* enter file name */
ShowMessage (CP[63]);
scanz ("%s", fname);
/* chess.000 */
if (fname[0] == '\0')
strcpy (fname, CP[137]);
if ((fd = fopen (fname, "r")) != NULL)
{
NewGame ();
fgets (fname, 256, fd);
computer = opponent = white;
InPtr = fname;
skip ();
if (*InPtr == 'c')
computer = black;
else
opponent = black;
skip ();
skip ();
skip ();
Game50 = atoi (InPtr);
fgets (fname, 256, fd);
InPtr = &fname[14];
castld[white] = ((*InPtr == CP[214][0]) ? true : false);
skip ();
skip ();
castld[black] = ((*InPtr == CP[214][0]) ? true : false);
fgets (fname, 256, fd);
InPtr = &fname[11];
skipb ();
TCflag = atoi (InPtr);
skip ();
InPtr += 14;
skipb ();
OperatorTime = atoi (InPtr);
fgets (fname, 256, fd);
InPtr = &fname[11];
skipb ();
TimeControl.clock